package com.ztc.ZtcClassesPriceForSale.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ztc.ZtcClassesPriceForSale.bean.ZtcClassesPriceForSale;
import com.ztc.ZtcClassesPriceForSale.dao.ZtcClassesPriceForSaleDao;
import com.ztc.ZtcOrder.bean.ZtcOrder;
import com.ztc.ZtcOrder.dao.ZtcOrderDao;
@Service("ZtcClassesPriceForSale")
public class ZtcClassesPriceForSaleManager {
    @Autowired
    ZtcClassesPriceForSaleDao ztcClassesPriceForSaleDao;
    @Autowired
    ZtcOrderDao ztcOrderDao;
    public String save(ZtcClassesPriceForSale ztcClassesPriceForSale){
    	return ztcClassesPriceForSaleDao.save(ztcClassesPriceForSale);
    }
    public String update(ZtcClassesPriceForSale ztcClassesPriceForSale){
    	return ztcClassesPriceForSaleDao.update(ztcClassesPriceForSale);
    }
    
    public List<ZtcClassesPriceForSale> getAll(){
        return ztcClassesPriceForSaleDao.getAllZtcClassesPriceForSales();
    }

    /**
     * 根据起始站点名称，结束站点名称，发车日期模糊查找在售班次价格信息
     * @param startSiteName 起始站点名称
     * @param endSiteName 结束站点名称
     * @param departureDate 发车日期
     * @return 售班次价格信息集合
     */
    public List<ZtcClassesPriceForSale> searchInfoLikes(String startSiteName,String endSiteName,String departureDate){
        List<ZtcClassesPriceForSale> list= ztcClassesPriceForSaleDao.searchInfoLikes(startSiteName, endSiteName,departureDate);
        return list;
    }
    public List<ZtcClassesPriceForSale> searchInfoEquals(ZtcClassesPriceForSale ztcPriceForSale) {
       return ztcClassesPriceForSaleDao.searchInfoEquals(ztcPriceForSale);
    }

    /**
     * 根据结束站点id查询在售班次价格信息
     * @param endSiteId 结束站点id
     * @return 在售班次价格信息
     */
    public List<ZtcClassesPriceForSale> searchByEndSiteId(String endSiteId){
    	ZtcClassesPriceForSale ztcPriceForSaleBean=new ZtcClassesPriceForSale();
    	ztcPriceForSaleBean.setFkEndClassesSiteForSaleId(endSiteId);
        List<ZtcClassesPriceForSale> list= ztcClassesPriceForSaleDao.searchInfoEquals(ztcPriceForSaleBean);
        for (ZtcClassesPriceForSale ztcPriceSaleForSale : list) {
        	ZtcOrder ztcOrder=new ZtcOrder();
        	ztcOrder.setFkZtcClassesPriceForSaleId(ztcPriceSaleForSale.getId());
			List<ZtcOrder> orders=ztcOrderDao.searchInfo(ztcOrder);
			ztcPriceSaleForSale.setZtcOrders(orders);
		}
        return list;
    }

    /**
     * 根据在售班次价格id或在售班次id或修改用户id删除在售班次价格
     * @param id 在售班次价格id
     * @param classesForSaleId 在售班次id
     * @param modifyUserId 修改用户id
     * @return 操作结果信息：0.修改失败，1.修改成功
     */
    public String delete(String id,String classesForSaleId,String modifyUserId){
        return ztcClassesPriceForSaleDao.delete(id,classesForSaleId,modifyUserId);
    }

    /**
     * 搜索发车时间+30天仍小于当前时间的在售班次价格
     * @return 在售班次价格集合
     */
    public List<ZtcClassesPriceForSale> searchOverduePriceForSale(){
        return ztcClassesPriceForSaleDao.searchOverduePriceForSale();
    }
    
}